package com.xtwy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @作 者: 侯建军
 * @日 期: 2018/7/28 18:31
 * @描 述:
 * @公 司：山西迅腾伟业
 */
@Controller
public class Home {

    /**
     * 查找权限中有没有admin
     * @param model
     * @return
     */
    @RequestMapping(value = {"/","/index"})
    @PreAuthorize("hasRole('admin')")
    public String index(Model model){
        model.addAttribute("key1","我的Java世界Security!!!");
        return "index";
    }

    /**
     * 登录界面
     * @return
     */
    @RequestMapping(value="/login" )
    public String login(){
        return"login";
    }

    @RequestMapping(value="/welcome")
    public String welcome(){
        return "welcome";
    }

    /**
     * 普通用户
     * @param model
     * @return
     */
    @RequestMapping(value = {"/news"})
    @PreAuthorize("hasRole('user')")
    public String news(Model model){
        return "news";
    }

    /**
     * 错误页面
     * @param model
     * @return
     */
    @RequestMapping(value = {"/myerror"})
    public String Myerror(Model model){
        return "myerror";
    }
}